package com.qinggeng.framework.config.mq.impl;

import com.alibaba.fastjson.JSONObject;
import com.qinggeng.common.exception.CustomException;
import com.qinggeng.framework.config.mq.dto.MessageAccountDTO;
import com.qinggeng.framework.config.mq.dto.MessageOrderPayDTO;
import com.qinggeng.framework.config.mq.handle.MessageHandle;
import com.qinggeng.project.api.security.utils.ApiUtils;
import com.qinggeng.project.system.service.IUserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageOrderPayImpl implements MessageHandle {

    @Autowired
    IUserAccountService userAccountService;
    @Override
    public void handle(String msg) {
        System.out.println("解析handle "+msg);
        try {
            MessageOrderPayDTO payDTO= JSONObject.parseObject(msg,MessageOrderPayDTO.class);
            Long messageId=payDTO.getMessageId();
            String orderNo=payDTO.getOrderNo();
            userAccountService.orderPayMoney(messageId,orderNo);
        }catch (Exception e){
            throw  new CustomException("消息解析错误 "+e.getMessage());
        }
    }
}
